package com.yyfax.pay.third.model.to.fuiou.xml;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxDriver;
import com.thoughtworks.xstream.io.xml.StaxWriter;
import com.yyfax.commons.json.JacksonUtil;

import java.io.StringWriter;

/**
 * 独立鉴权，
 * 
 * @author xulqb
 * @date 2017-02-22 10:03:59
 * @since v1.0.0
 */
@XStreamAlias("FM")
public class QueryPayWithoutVerifyData {

	/**
	 * 商户代码
	 */
	@XStreamAlias("MchntCd")
	private String mchntcd;


	/**
	 * 版本号
	 */
	@XStreamAlias("Ver")
	private String version;


	/**
	 * 商户订单号
	 */
	@XStreamAlias("MCHNTORDERID")
	private String mchntorderid;

	/**
	 * 商户流水号
	 */
	@XStreamAlias("OSsn")
	private String oSsn;

	/**
	 * 银行卡号
	 */
	@XStreamAlias("Ono")
	private String ono;

	/**
	 * 姓名
	 */
	@XStreamAlias("Onm")
	private String onm;

	/**
	 * 卡证件类型
	 */
	@XStreamAlias("OCerTp")
	private String oCerTp;

	/**
	 * 证件号
	 */
	@XStreamAlias("OCerNo")
	private String oCerNo;

	/**
	 * 银行预留手机号
	 */
	@XStreamAlias("Mno")
	private String mno;

	/**
	 * MchntCd + "|" + Ver + "|" + OSsn + "|" + Ono + "|" + OCerTp + "|" + OCerNo + "|" +mchnt_key
	 * 做md5摘要 其中mchnt_key为32位的商户密钥，系统分配
	 */
	@XStreamAlias("Sign")
	private String sign;

	public String getMchntcd() {
		return mchntcd;
	}

	public void setMchntcd(String mchntcd) {
		this.mchntcd = mchntcd;
	}

	public String getVersion() {
		return version;
	}

	public void setVersion(String version) {
		this.version = version;
	}

	public String getMchntorderid() {
		return mchntorderid;
	}

	public void setMchntorderid(String mchntorderid) {
		this.mchntorderid = mchntorderid;
	}

	public String getoSsn() {
		return oSsn;
	}

	public void setoSsn(String oSsn) {
		this.oSsn = oSsn;
	}

	public String getOno() {
		return ono;
	}

	public void setOno(String ono) {
		this.ono = ono;
	}

	public String getOnm() {
		return onm;
	}

	public void setOnm(String onm) {
		this.onm = onm;
	}

	public String getoCerTp() {
		return oCerTp;
	}

	public void setoCerTp(String oCerTp) {
		this.oCerTp = oCerTp;
	}

	public String getMno() {
		return mno;
	}

	public void setMno(String mno) {
		this.mno = mno;
	}

	public String getSign() {
		return sign;
	}

	public void setSign(String sign) {
		this.sign = sign;
	}

	public String getoCerNo() {
		return oCerNo;
	}

	public void setoCerNo(String oCerNo) {
		this.oCerNo = oCerNo;
	}

	@Override
	public String toString() {
		return JacksonUtil.nonullMapper.toJson(this);
	}

	/**
	 * 该实体转换成XML字符串
	 * 
	 * @author xulqb
	 * @date 2017-02-22 10:03:59
	 * @since v1.0.0
	 * @return 返回XML字符串
	 */
	public String toXml() {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("FM", QueryPayWithoutVerifyData.class);
		try {
			StringWriter strWriter = new StringWriter();
			// don't do startDocument and do repair namespaces
			StaxWriter sw = new StaxWriter(staxDriver.getQnameMap(), staxDriver.getOutputFactory().createXMLStreamWriter(strWriter), false, true);
			xstream.marshal(this, sw);
			sw.close();
			// return "<?xml version=\"1.0\" encoding=\"utf-8\"?>" + strWriter.toString();
			return strWriter.toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * XML字符串转换成实体{@link QueryPayWithoutVerifyData}
	 * 
	 * @author xulqb
	 * @date 2017-02-22 10:03:59
	 * @since v1.0.0
	 * @param xml
	 * @return 返回{@link QueryPayOrderData}
	 */
	public static QueryPayWithoutVerifyData fromXml(String xml) {
		QNameMap qmap = new QNameMap();
		qmap.setDefaultPrefix("");
		StaxDriver staxDriver = new StaxDriver(qmap);
		XStream xstream = new XStream(staxDriver);
		xstream.autodetectAnnotations(true);
		xstream.ignoreUnknownElements();
		xstream.alias("FM", QueryPayWithoutVerifyData.class);
		return (QueryPayWithoutVerifyData) xstream.fromXML(xml);
	}
}
